package com.scpii.universal.dispatch.thread;

import java.util.concurrent.Callable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.scpii.universal.concurrent.Callback;
import com.scpii.universal.dispatch.Const;
import com.scpii.universal.dispatch.domain.CompileTask;
import com.scpii.universal.dispatch.tools.PackTool;

/**
 * 打包线程
 * 
 * @author chenxin
 * 
 */
public class PackThread implements Callable<Void> {
	private static final Logger logger = LoggerFactory
			.getLogger(PackThread.class);

	private final CompileTask task;

	private final Callback callback;

	private final PackTool packTool;

	public PackThread(CompileTask task, Callback callback, PackTool packTool) {
		this.task = task;
		this.callback = callback;
		this.packTool = packTool;
	}

	@Override
	public Void call() {
		int action = Const.COMPLETE_PACK_ACTION;
		Integer taskid = task.getCompileTaskId();
		try {
			logger.info("打包开始,taskid = " + taskid);
			packTool.pack(task);
			callback.handleMessage(action, task);
			logger.info("打包结束,taskid = " + taskid);
		} catch (Exception e) {
			logger.info("package error,taskid = " + taskid, e);
			action = Const.UNCOMPLETE_PACK_ACTION;
			callback.handleMessage(action, task, e.getMessage());
		} finally {

		}
		return null;

	}

}